home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / mysql-test / t / case.test < prev    next >
Encoding:
Text File  |  2003-01-21  |  1.7 KB  |  38 lines  |  [TEXT/ttxt]

  1. #
  2. # Testing of CASE
  3. #
  4.  
  5. drop table if exists t1;
  6.  
  7. select CASE "b" when "a" then 1 when "b" then 2 END;
  8. select CASE "c" when "a" then 1 when "b" then 2 END;
  9. select CASE "c" when "a" then 1 when "b" then 2 ELSE 3 END;
  10. select CASE BINARY "b" when "a" then 1 when "B" then 2 WHEN "b" then "ok" END;
  11. select CASE "b" when "a" then 1 when binary "B" then 2 WHEN "b" then "ok" END;
  12. select CASE concat("a","b") when concat("ab","") then "a" when "b" then "b" end;
  13. select CASE when 1=0 then "true" else "false" END;
  14. select CASE 1 when 1 then "one" WHEN 2 then "two" ELSE "more" END;
  15. select CASE 2.0 when 1 then "one" WHEN 2.0 then "two" ELSE "more" END;
  16. select (CASE "two" when "one" then "1" WHEN "two" then "2" END) | 0;
  17. select (CASE "two" when "one" then 1.00 WHEN "two" then 2.00 END) +0.0;
  18. select case 1/0 when "a" then "true" else "false" END;
  19. select case 1/0 when "a" then "true" END;
  20. select (case 1/0 when "a" then "true" END) | 0;
  21. select (case 1/0 when "a" then "true" END) + 0.0;
  22. select case when 1>0 then "TRUE" else "FALSE" END;
  23. select case when 1<0 then "TRUE" else "FALSE" END;
  24.  
  25. #
  26. # Test bug when using GROUP BY on CASE
  27. #
  28. create table t1 (a int);
  29. insert into t1 values(1),(2),(3),(4);
  30. select case a when 1 then 2 when 2 then 3 else 0 end as fcase, count(*) from t1 group by fcase;
  31. select case a when 1 then "one" when 2 then "two" else "nothing" end as fcase, count(*) from t1 group by fcase;
  32. drop table t1;
  33. drop table if exists t;
  34. create table t1 (row int not null, col int not null, val varchar(255) not null);
  35. insert into t1 values (1,1,'orange'),(1,2,'large'),(2,1,'yellow'),(2,2,'medium'),(3,1,'green'),(3,2,'small');
  36. select max(case col when 1 then val else null end) as color from t1 group by row;
  37. drop table if exists t;
  38.